package net.googlecode.exigenlab.task3;

import java.math.BigDecimal;

/**
 * Created by IntelliJ IDEA.
 * User: dima
 * Date: 3/25/11
 * Time: 8:37 PM
 * To change this template use File | Settings | File Templates.
 */
public class SalaryCalculator {

    public BigDecimal calc(Object person) {
        BigDecimal salary = new BigDecimal(0);

        BigDecimal manTax = new BigDecimal(250);
        BigDecimal empTax = new BigDecimal(125);

        if (person instanceof Manager) {
            Manager m = (Manager) person;

            System.out.println("Manager: " + m.name());
            if (m.perHour()) {
                //170 hours in month
                salary = new BigDecimal(170).multiply(m.rate);
            } else {
                salary = m.rate;
            }

            if (m.bonus()) {
                salary = salary.add(m.bonusAmt);
            }

            salary = salary.subtract(manTax);
        } else if (person instanceof Employee) {
            Employee e = (Employee) person;

            System.out.println("Employee: " + e.name());
            if (e.perHour()) {
                //170 hours in month
                salary = new BigDecimal(170).multiply(e.rate);
            } else {
                //salary = rate * experience
                salary = e.rate.multiply(new BigDecimal(e.experience));
            }

            if (e.bonus()) {
                salary = salary.add(e.bonusAmT);
            }
            salary = salary.subtract(empTax);
        }

        return salary;
    }
}
